package com.dyna.cp.binlog.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.dyna.constants.DateFatter;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@TableName("bin_log_history")
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("Binlog增删改操作记录")
public class BinLogEntity {

    @ApiModelProperty("主键id")
    @TableId(type = IdType.AUTO)
    private  Integer id;

    @ApiModelProperty("操作类型")
    private String type;

    @ApiModelProperty("操作库")
    private String dbName;

    @ApiModelProperty("操作表")
    private String tableName;

    @ApiModelProperty("操作前")
    @TableField(insertStrategy= FieldStrategy.NOT_NULL)
    private String beforeData;

    @ApiModelProperty("操作后")
    @TableField(insertStrategy= FieldStrategy.NOT_NULL)
    private String afterData;

    @ApiModelProperty("操作时间")
    @JsonFormat(pattern = DateFatter.YYYY_MM_DD_HH_MM_SS)
    private LocalDateTime createTime;

    public BinLogEntity(String type, String database, String table, String before, String after) {
        this.type = type;
        this.dbName = database;
        this.tableName = table;
        this.beforeData = before;
        this.afterData = after;
        this.createTime = LocalDateTime.now();
    }
}
